﻿
Partial Class index
    Inherits System.Web.UI.Page

    Private Const DomainName As String = "localhost:49945"

    Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init

        btnGo.Style("width") = "100%"
        fdTargetURL.Style("float") = "left"
        lblTargetURL.Style("float") = "left"

    End Sub

    Protected Sub btnGo_Click(sender As Object, e As System.EventArgs) Handles btnGo.Click

        Dim HTML As String = GetPage(fdTargetURL.Text)
        AddJavascriptReference(HTML)

        Response.Write(HTML)
        Response.End()

    End Sub

    Private Function GetPage(URL As String) As String

        Dim webClient As System.Net.WebClient = New System.Net.WebClient()
        Dim result As String = webClient.DownloadString(URL)

        Return result

    End Function

    Private Sub AddJavascriptReference(ByRef HTML As String)

        If Not HTML.ToLower.ToLower.Contains("jquery") Then
            HTML = HTML.Replace("</head>", "<script type='text/javascript' src='http://" & DomainName & "/JS/jquery-1.4.3.js'></script></head>")
        End If

        HTML = HTML.Replace("</head>", "<script type='text/javascript' src='http://" & DomainName & "/JS/exploding.js'></script></head>")

    End Sub

End Class
